<template>
  <div id="historyScore" class="">
    <Myheader :page="page"></Myheader>

    <div class="">
      <divider>您共有{{scoreNum}}条成绩记录</divider>
      <group :title="item.race" v-for="(item, index) in scoreList" :key="item.id">
        <cell :title="$t('姓名')" :value="item.name">
        </cell>
        <cell :title="$t('比赛时间')" :value="item.racetime">
        </cell>
        <cell :title="$t('项目')" :value="item.event">
        </cell>
        <cell :title="$t('净成绩')" :value="item.nettime">
        </cell>
        <cell :title="$t('枪声成绩')" :value="item.time">
        </cell>
        <cell v-if="item.level" :title="$t('等级')" :value="item.level">
        </cell>

      </group>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
import Myheader from "@/common/components/myheader.vue";
import { CheckIcon, XButton, Group, Cell, ViewBox, Divider } from "vux";
//axios
import qs from "qs";
import { axios } from "@/api/axios.js";
import { indexedDB } from "@/api/indexedDB.js";
import mixin from "@/common/js/mixin";
export default {
  mixins: [mixin],
  props: ["page", "host"],
  components: {
    Group,
    Cell,
    XButton,
    ViewBox,
    Divider,
    Myheader
  },
  data() {
    return {
      idnum: "",
      key: "",
      scoreList: [],
      scoreNum: ""
    };
  },
  created() {
    indexedDB(
      "IDNumber",
      "get",
      this.RACEID,
      "",
      function(a) {
        this.idnum = a;
        //this.idnum= '332624198911230033';
        this.userApply();
      }.bind(this)
    );
  },
  methods: {
    userApply() {
      this.axios
        .post(
          `${window.host}registration/fetch`,
          qs.stringify({
            idnum: this.idnum,
            raceid: this.RACEID
          })
        )
        .then(response => {
          if (response.data.code == "200") {
            if (response.data.data.length == 0) {
              this.$vux.toast.show({
                type: "warn",
                text: this.$t("index.nofound"),
                onHide() {
                  this.$router.push("/message");
                }
              });
            } else {
              this.key = response.data.data[0]._key;
              this.getHistory();
            }
          } else {
            this.$vux.toast.show({
              type: "warn",
              text: response.data.msg,
              onHide() {
                this.$router.push("/message");
              }
            });
          }
        });
    },
    getHistory() {
      let _this = this;
      this.axios
        .post(
          `${window.host}registration/score`,
          qs.stringify({
            id: this.key
          })
        )
        .then(response => {
          if (response.data.code == "200") {
            this.scoreList = response.data.data;
            this.scoreNum = this.scoreList.length;
            if (this.scoreList.length == 0) {
              this.$vux.toast.show({
                type: "warn",
                text: this.$t("您还没有历史成绩"),
                onHide() {
                  _this.$router.push("/message");
                }
              });
            }
          } else {
            this.$vux.toast.show({
              type: "warn",
              text: response.data.msg,
              onHide() {
                this.$router.push("/message");
              }
            });
          }
        });
    }
  }
};
</script>

<style>
html,
body {
  height: auto;
}

#tabbar .weui-tabbar {
  position: fixed;
}
</style>
